

let vm = new Vue({
    el:'#app',
    data:{
        goods:[
          {id:1,name:'iphone12',price:8765,count:1,time:new Date()},  
          {id:2,name:'iphone8',price:7765,count:1,time:new Date()},  
          {id:3,name:'iphone6',price:6765,count:1,time:new Date()},  
          {id:4,name:'iphone4',price:5765,count:1,time:new Date()},  
          {id:5,name:'iphoneX',price:4765,count:1,time:new Date()}  
        ],
        goodID:null,
        goodName:null,
        key:''
    },
    methods: {
        add(){
          let id = this.goods[this.goods.length-1].id+1
          this.goods.push({
              id:id,
              name:this.goodName,
              time:new Date()
          }) 
        //   添加完成 后，清空输入框的值 
          this.goodName=null
        },
        remove(index){
            this.goods.splice(index,1)
        }
    },
    filters:{
        dateFormat(date){
            let dateObj = new Date(date)
            let fullYear = dateObj.getFullYear()
            let month = (dateObj.getMonth()+1).toString().padStart(2,0)
            let day = dateObj.getDate().toString().padStart(2,0)
            let hour = dateObj.getHours().toString().padStart(2,0)
            let minute = dateObj.getMinutes().toString().padStart(2,0)
            let seconds = dateObj.getSeconds().toString().padStart(2,0)

            return `${fullYear}-${month}-${day} ${hour}:${minute}:${seconds}`
        }
    },
    computed: {
        search(){
            return this.goods.filter((item)=>{
                return item.name.includes(this.key)
            })
        }
    },
})